package com.grandtech.insurance.common.utils;

import org.apache.commons.lang.StringUtils;

import java.util.Map;

/**
* @Description:    判空
* @Author:         han bo
* @CreateDate:     2019/7/1 10:15
* @UpdateUser:
* @UpdateDate:     2019/7/1 10:15
* @UpdateRemark:
* @Version:        1.0
*/
public class EmptyUtil {
    private static  final String ERROR_EMPTY="必填参数为空";
    /**
     * 判断字符串是否为空，空则抛出异常
     * @param text
     * @throws Exception
     */
    public static void emptyVerifi(String text) throws Exception {
        if(StringUtils.isBlank(text)){
            throw new Exception(ERROR_EMPTY);
        }
    }
    /**
     * 判断字符串是否为空，空则抛出异常
     * @param text
     * @throws Exception
     */
    public static void emptyVerifi(String text,String message) throws Exception {
        if(StringUtils.isBlank(text)){
            throw new Exception(message);
        }
    }
    /**
     * 判断float是否为0，空则抛出异常
     * @param number
     * @throws Exception
     */
    public static void emptyVerifi(float number) throws Exception {
        if(number==0.0f){
            throw new Exception(ERROR_EMPTY);
        }
    }
    /**
     * 判断float是否为0，空则抛出异常
     * @param number
     * @throws Exception
     */
    public static void emptyVerifi(long number) throws Exception {
        if(number==0L){
            throw new Exception(ERROR_EMPTY);
        }
    }

    /**
     * 验证map中是否含有某个key
     * @throws Exception
     */
    public static void emptyVerifi(Map<String, Object> map, String key) throws Exception {
        if(!map.containsKey(key)){
            throw new Exception(ERROR_EMPTY);
        }
    }
    /**
     * 验证对象是否为空
     * @throws Exception
     */
    public static void emptyVerifi(Object object) throws Exception {
        if(object==null){
            throw new Exception(ERROR_EMPTY);
        }
    }

}
